<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>短信模板配置</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link href="../../layui/css/iconfont/iconfont.css" rel="stylesheet" type="text/css">
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>

    <script>
        layui.use(['form', 'jquery', 'element', 'laydate', 'layer'], function () {
            var form = layui.form;
            var $ = layui.$;
            var laydate = layui.laydate;
            var layer = layui.layer;
            var mgrId = getUrlParam("mgrId");

            laydate.render({
                elem: '#startTime'
                , type: 'datetime'
            });
            laydate.render({
                elem: '#endTime'
                , type: 'datetime'
            });

            laydate.render({
                elem: '#thresholdStartTime'
            });
            laydate.render({
                elem: '#thresholdEndTime'

            });
            laydate.render({
                elem: '#everyDayStartTime'
                , type: 'time'
                , value: '08:00:00'
                , btns: ['clear', 'confirm']
            });
            laydate.render({
                elem: '#everyDayEndTime'
                , type: 'time'
                , value: '20:00:00'
                , btns: ['clear', 'confirm']
            });


            function submit(parm) {
                layer.confirm('确认模板信息无误吗？是否需要再次查看', {
                    btn: ['不需要', '需要'] //按钮
                }, function () {
                    $.ajax({
                        type: 'post',
                        data: parm,
                        url: "/template/configure",
                        beforeSend: function () {
                            loading = layer.load(0, {shade: false});
                        },
                        success: function (json) {
                            layer.close(loading);

                            if (json.code == 0) {
                                layui.use('layer', function () {
                                    layer.msg('配置成功,点击确认返回模板配置管理界面', {
                                        time: 0 //不自动关闭
                                        , btn: ['确定']
                                        , yes: function (index) {
                                            layer.close(index);
                                            location.href = "smsTemplateManage.html";
                                        }
                                    });
                                });
                            } else {
                                layer.msg(json.msg);
                            }
                        },
                        complete: function () {

                        },
                        error: function (data) {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    });
                });
            }

            form.on('radio(localDate1)', function(data){
                if(data.value==0||data.value==2){
                    console.info(data.value);
                    $("#local").show();
                }else {
                    console.info(data.value);
                    $("#local").hide();
                }
                if(data.value==1||data.value==2){
                    console.info(data.value);
                    $("#province").show();
                }else {
                    console.info(data.value);
                    $("#province").hide();
                }
            });

            $('#submit').on('click', function () {
                var thresholdStartTime = $("#thresholdStartTime").val();  //时间范围内的开始时间
                var thresholdEndTime = $("#thresholdEndTime").val();    //时间范围内的结束时间
                var cycle = $("input[name='cycle']:checked").val();     //发送周期
                //阀值的形式
                var isThreshold = 0;
                $("input:checkbox[name='isThreshold']:checked").each(function () {
                    isThreshold += parseInt($(this).val());
                });
                var parm = {
                    mgrId: mgrId,
                    startTime: $("#startTime").val(),   //项目开始时间
                    endTime: $("#endTime").val(),//结束时间
                    everyDayStartTime: $("#everyDayStartTime").val(),//每天发送的开始时间
                    everyDayEndTime: $("#everyDayEndTime").val(), //每天发送的结束时间
                    isLocal: $("input[name='isLocal']:checked").val(),//是否本地发送
                    realTime: $("input[name='realTime']:checked").val(), //延时
                    threshold: $("#threshold").val(),  //全部阀值
                    cycle: cycle,//发送周期
                    cycleThreshold: $("#cycleThreshold").val(),//周期阀值
                    thresholdStartTime: thresholdStartTime, //时间范围内的开始时间
                    thresholdEndTime: thresholdEndTime, //时间范围内的结束时间
                    isThreshold: isThreshold,
                    flag: "insert",
                    localDate: $("input[name='localDate']:checked").val(),//本地发送保存时间
                    isProvince: $("input[name='isProvince']:checked").val()//发送范围判断
                };
                if ($("#everyDayStartTime").val() == null || $("#everyDayStartTime").val() == "") {
                    layer.msg("每日发送开始时间不能为空");
                    return false;
                }
                if ($("#everyDayEndTime").val() == null || $("#everyDayEndTime").val() == "") {
                    layer.msg("每日发送结束时间不能为空");
                    return false;
                }
                if (cycle == 5) {
                    if (isNull(thresholdStartTime) || isNull(thresholdEndTime)) {
                        layer.msg("请选择周期阀值的时间");
                        return false;
                    }
                }
                if (!checkRate($("#threshold").val())) {
                    layer.msg("阀值必须为数字");
                    return false;
                }
                if (!checkRate($("#cycleThreshold").val())) {
                    layer.msg("阀值必须为数字");
                    return false;
                }
                if ($("#startTime").val() == null || $("#startTime").val() == "") {
                    layer.msg("发送开始时间不能为空");
                    return false;
                }
                if (isThreshold < 2 && $("#cycleThreshold").val() > 0) {
                    layer.confirm('短信周期发送量大于0，但并未勾选\'周期短信发送量\',按周期设置阀值不会生效,您是否要继续？', {
                        btn: ['继续', '取消'] //按钮
                    }, function () {
                        submit(parm);
                    });
                    return false;
                };

                if (isThreshold != 1 && isThreshold != 3 && $("#threshold").val() > 0) {
                    layer.confirm('短信发送总条数大于0，但并未勾选\'短信发送总量\',总量阀值设置不会生效,您是否要继续？', {
                        btn: ['继续', '取消']//按钮
                    }, function () {
                        submit(parm);
                    });
                    return false;
                } else {
                    submit(parm);
                }

            });
        });


    </script>
</head>
<body>
<!--nav-->
<div class="layui-html-limit">
    <!--container-->
    <div class="layui-content-body">
        <div class="scroll-box">
            <div class="breadcrumb-box">
              <span class="layui-breadcrumb" lay-separator="|">
      <a href="javascript:returnIndex2()">首页&nbsp;</a>
  <a href=""> &nbsp;短信模板管理&nbsp; </a>
  <a href="smsTemplateManage.html"> &nbsp;短信项目模板配置管理</a>
  <a href=""> &nbsp;短信项目模板配置&nbsp; </a>
</span>
            </div>
            <div class="content-box">
                <div class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <div class="layui-block">
                            <label class="layui-form-label" style="width: auto">发送起止时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="date" id="startTime" autocomplete="off" class="layui-input"
                                       placeholder="请选择" lay-verify="required">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline">
                                <input type="text" name="date" id="endTime" autocomplete="off" class="layui-input"
                                       placeholder="请选择">
                            </div>
                            <div class="layui-inline">(结束时间可以为空,代表永久有效)</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-block">
                            <label class="layui-form-label" style="width:auto">每日发送时间段</label>
                            <div class="layui-input-inline">
                                <input type="text" name="date" id="everyDayStartTime" autocomplete="off"
                                       class="layui-input"
                                       placeholder="请选择">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline">
                                <input type="text" name="date" id="everyDayEndTime" autocomplete="off"
                                       class="layui-input"
                                       placeholder="请选择">
                            </div>
                            <div class="layui-inline">(若想在发送起止时间内连续发送，请将每日发送时间段置为00:00:00至23:59:59)</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-block" pane="">
                            <label class="layui-form-label">发送实时性</label>
                            <div class="layui-input-block">
                                <input type="radio" name="realTime" value="0" title="立即发送">
                                <input type="radio" name="realTime" value="5" title="延迟5分钟发送">
                                <input type="radio" name="realTime" value="10" title="延迟10分钟发送">
                                <input type="radio" name="realTime" value="20" title="延迟20分钟发送" checked="">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-block" pane="">
                            <label class="layui-form-label" style="width: auto">号码发送范围</label>
                            <div class="layui-input-block">
                                <input type="radio" name="isLocal" value="0" title="本地" lay-filter="localDate1">
                                <input type="radio" name="isLocal" value="1" title="外地" lay-filter="localDate1">
                                <input type="radio" name="isLocal" value="2" title="本地+外地" lay-filter="localDate1">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item hiden" id="local" style="display: none">
                        <div class="layui-block" pane="">
                            <label class="layui-form-label" style="width: auto">本地号码保存时间</label>
                            <div class="layui-input-block">
                                <input type="radio" name="localDate" value="7" title="7天" checked="">
                                <input type="radio" name="localDate" value="15" title="15天">
                                <input type="radio" name="localDate" value="30" title="30天">
                                <input type="radio" name="localDate" value="90" title="90天">
                                <input type="radio" name="localDate" value="180" title="180天">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item hiden" id="province" style="display: none">
                        <div class="layui-block" pane="">
                            <label class="layui-form-label" style="width: auto">外地发送范围</label>
                            <div class="layui-input-block">
                            <input type="radio" name="isProvince" value="0" title="省内" >
                            <input type="radio" name="isProvince" value="1" title="省内+省外" checked="">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="width: auto">短信发送量阀值设置</label>
                        <div class="layui-inline">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <input type="checkbox" name="isThreshold" title="短信发送总量" value="1">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline" pane="">
                                    <label class="layui-form-label" style="width: auto">短信发送总条数:</label>
                                    <div class="layui-input-inline" style="width: auto">
                                        <input type="text" id="threshold" placeholder="请输入"
                                               autocomplete="off" class="layui-input" value="0">
                                    </div>
                                </div>
                                <div class="layui-inline">条</div>
                            </div>
                            <div class="layui-form-item">
                                <input type="checkbox" name="isThreshold" title="周期短信发送量" value="2">
                            </div>
                            <div class="layui-inline" pane="">
                                <input type="radio" name="cycle" value="1" title="按年" checked>
                                <input type="radio" name="cycle" value="2" title="按月">
                                <input type="radio" name="cycle" value="3" title="按周">
                                <input type="radio" name="cycle" value="4" title="按日">
                                
                                
                            </div>
                            <div class="layui-form-item">
                             <h4 class="tips-h4"><i class="iconfont icon-xinxi"></i>
                                                            周发送量不是当天的起，是该周周一开始计算，月发送量就是从当月一号开始算。   </h4>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-form-item">
                                    <div class="layui-inline" pane="">
                                        <label class="layui-form-label">短信发送量:</label>
                                        <div class="layui-input-inline" style="width: 100px;">
                                            <input type="text"
                                                   placeholder="请输入" id="cycleThreshold"
                                                   autocomplete="off" class="layui-input"
                                                   value="0">
                                        </div>
                                    </div>
                                    <div class="layui-inline">条</div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn" id="submit">立即提交</button>
                    </div>
                </div>
                <h4 class="tips-h4"><i class="iconfont icon-xinxi"></i>
                    地市短信项目管理员设置或者修改模板属性提交后短信通知省公司管理员审核，审核通过后设置或者修改属性才能生效
                </h4>
            </div>
        </div>
    </div>
</div>
</body>
</html>